<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/vue.js"></script>
</head>
<body>
<div id="div_id">
    <h2>总价格：{{price}}</h2>
</div>

<script>
    const app=new Vue({
        el:"#div_id",
        data:{
            books:[
                {id:100,name:"123",price:10},
                {id:101,name:"456",price:20},
                {id:102,name:"789",price:30},
                {id:103,name:"012",price:40}
            ]
        },
        computed:{
            price:function () {
                var bks=this.books;
                var p=0;
                for(var i=0;i<bks.length;i++){
                    p+=bks[i].price;
                }
                return p;
            }
        }
    })
</script>
</body>
</html>